namespace FastDevTemplate.Common.Util;

public abstract class TimerTask
{
    protected readonly Poller Poller;
    
    protected readonly TimerTaskEventArgs Args = new TimerTaskEventArgs();
    
    public TimerTaskEventArgs GetArgs => Args;
    protected abstract void PollerExecute(TimerTaskEventArgs args);

    protected TimerTask(int millisecondsTimeout)
    {
        Poller = new Poller( () =>
        {
            PollerExecute(Args);
            Args.Update();
        }, millisecondsTimeout);
    }

    public virtual TimerTask Start()
    {
        Poller.Run();
        return this;
    }
    
    public virtual TimerTask Stop()
    {
        Poller.Kill();
        return this;
    }
    
}
